Repository navigation
Conversation
Add aai.Diarizer and aai.AsyncDiarizer for POST /v1/diarize on diarization.assemblyai.com (US/EU data-residency hosts via settings.diarization_base_url). diarize(audio, transcript=None, config=None, *, content_type=None) posts a buffered multipart body (Content-Length is required by the API) with the audio, an optional JSON transcript (a SyncTranscriptResponse, a dict with words, or a list of words) and an optional DiarizationConfig. Omitting the transcript runs segments-only mode. The audio Content-Type is inferred from the extension (shared with Dictation), audio/pcm when sample_rate/channels are set, and can be overridden. problem+json errors map to DiarizationError through the sync API's shared parser. Bumps the version to 1.11.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Organization and layout looks great to me. Here are a couple of things my agent found to take a look at: Bug: a dict transcript with SyncWord items isn't serializable (diarization/v1/_base.py, _transcript_json) Suggestion: check transcripts without timings before the upload Docstring: resolve_request lists the wrong precedence |
Adds a client for the standalone Diarization API (
POST /v1/diarize), which labels the speakers in an audio file.What's added
aai.Diarizerandaai.AsyncDiarizerwithdiarize(audio, transcript=None, config=None, *, content_type=None). They follow the layout of the TTS and Dictation clients.SyncTranscriptResponse(requested withtimestamps=True), a dict withwords, or a list of words. Each word comes back with a speaker and the words are grouped into utterances.transcriptto get speaker turns (segments) andspeakers. Diarization can then run in parallel with transcription.DiarizationConfig(sample_rate,channels,language_code; unknown fields are rejected) andDiarizationResponse(words,utterances,segments,speakers,audio_duration_ms,session_id,request_time_ms).DiarizationErroris built by the existing problem+json mapper (sync/v1/api.py::_error_from_response). It carriesstatus_code,error_codeandretry_after.diarization_base_urldefaults tohttps://diarization.assemblyai.com. Set it tohttps://diarization.us.assemblyai.comorhttps://diarization.eu.assemblyai.comto keep requests in that data zone.diarization_http_timeoutdefaults to 330 s: the server's 300 s inference timeout plus its 10 s queue wait, with margin.sample_rate/channelssendsaudio/pcm.content_type=overrides both. The body is a buffered multipart upload soContent-Lengthis always set; the API returns 411 without it.CLAUDE.mdentries;Testing
pytest -n auto -q: 1076 passed, 42 of them new (tests/unit/test_diarization.py,test_diarization_async.py). The new tests cover:api_key=.py311-latest,py312-latest,py311-httpx0.22,py311-httpx0.24,py311-pydantic1.10andpy311-websockets11.0all pass. The legacy envs caught two real bugs, both fixed:strmultipart parts;ruff format --checkandruff checkpass, andcheck_api_docs.pyreports "API reference OK".Notes for review
Diarizer/AsyncDiarizer/Diarization*. Happy to rename to match house style.tort.wordsrather than{"words": t.words}.dictation.v1._base, the same pattern as Dictation importing the sync error parser.The API itself is live in us-west-2 and eu-west-1. Docs: AssemblyAI/assemblyai-docs#584 (in review; its samples will use this client).
🤖 Generated with Claude Code